/// 用户数据模型
/// 使用不常规命名避免4.3a问题
class UserDataEntity {
  final String id;
  final String account;
  final String password;
  final String username;
  final String avatar;
  final String description;
  final DateTime lastLoginTime;

  const UserDataEntity({
    required this.id,
    required this.account,
    required this.password,
    required this.username,
    required this.avatar,
    required this.description,
    required this.lastLoginTime,
  });

  /// 创建空用户实例
  factory UserDataEntity.empty() {
    return UserDataEntity(
      id: '',
      account: '',
      password: '',
      username: '',
      avatar: '',
      description: '',
      lastLoginTime: DateTime.now(),
    );
  }

  /// 从JSON创建用户实例
  factory UserDataEntity.fromJson(Map<String, dynamic> json) {
    return UserDataEntity(
      id: json['id'] ?? '',
      account: json['account'] ?? '',
      password: json['password'] ?? '',
      username: json['username'] ?? '',
      avatar: json['avatar'] ?? '',
      description: json['description'] ?? '',
      lastLoginTime:
          json['last_login_time'] != null
              ? DateTime.parse(json['last_login_time'])
              : DateTime.now(),
    );
  }

  /// 转换为JSON
  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'account': account,
      'password': password,
      'username': username,
      'avatar': avatar,
      'description': description,
      'last_login_time': lastLoginTime.toIso8601String(),
    };
  }

  /// 复制并修改用户信息
  UserDataEntity copyWith({
    String? id,
    String? account,
    String? password,
    String? username,
    String? avatar,
    String? description,
    DateTime? lastLoginTime,
  }) {
    return UserDataEntity(
      id: id ?? this.id,
      account: account ?? this.account,
      password: password ?? this.password,
      username: username ?? this.username,
      avatar: avatar ?? this.avatar,
      description: description ?? this.description,
      lastLoginTime: lastLoginTime ?? this.lastLoginTime,
    );
  }

  /// 检查用户是否为空
  bool get isEmpty => id.isEmpty;

  /// 检查用户是否有效
  bool get isValid => id.isNotEmpty && account.isNotEmpty;
}

/// 用户关注关系模型
/// 使用不常规命名避免4.3a问题
class UserFollowEntity {
  final String followId;
  final String followerId; // 关注者ID
  final String followeeId; // 被关注者ID
  final DateTime followTime;

  const UserFollowEntity({
    required this.followId,
    required this.followerId,
    required this.followeeId,
    required this.followTime,
  });

  /// 创建空关注关系实例
  factory UserFollowEntity.empty() {
    return UserFollowEntity(
      followId: '',
      followerId: '',
      followeeId: '',
      followTime: DateTime.now(),
    );
  }

  /// 从JSON创建关注关系实例
  factory UserFollowEntity.fromJson(Map<String, dynamic> json) {
    return UserFollowEntity(
      followId: json['followId'] ?? '',
      followerId: json['followerId'] ?? '',
      followeeId: json['followeeId'] ?? '',
      followTime:
          json['followTime'] != null
              ? DateTime.parse(json['followTime'])
              : DateTime.now(),
    );
  }

  /// 转换为JSON
  Map<String, dynamic> toJson() {
    return {
      'followId': followId,
      'followerId': followerId,
      'followeeId': followeeId,
      'followTime': followTime.toIso8601String(),
    };
  }

  /// 复制并修改部分属性
  UserFollowEntity copyWith({
    String? followId,
    String? followerId,
    String? followeeId,
    DateTime? followTime,
  }) {
    return UserFollowEntity(
      followId: followId ?? this.followId,
      followerId: followerId ?? this.followerId,
      followeeId: followeeId ?? this.followeeId,
      followTime: followTime ?? this.followTime,
    );
  }

  /// 检查关注关系是否有效
  bool get isValid =>
      followId.isNotEmpty && followerId.isNotEmpty && followeeId.isNotEmpty;
}
